<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
{{include file="layouts/_head"}}
</head>
<body>
<div class="main">
    <ol class="breadcrumb">
        <li><i class="icon_home iconfont"></i>首页</li>
        <li>版块管理</li>
        <li class="active">版块列表</li>
    </ol>
    <div class="main-head text-left">
        <form class="form-inline" action="{{:url('/admin/section')}}" method="get">
            <select class="form-control" name="client">
                <option value="">客户端</option>
                {{volist name="clientArray" id="vo"}}
                <option value="{{$key}}" {{if Request()->client == $key}} selected {{/if}}>{{$vo}}</option>
                {{/volist}}
            </select>
            <input type="text" class="form-control" name="keyword" value="{{:Request()->keyword}}" placeholder="版块名" >
            <button type="submit" class="btn btn-primary">搜索</button>
        </form>
    </div>
    <div class="bg-1 clearfix main-head-info">
        <a href="{{:url('/admin/section/create')}}" class="btn btn-success btn-sm">创建版块</a>
        <button type="submit" class="btn btn-danger btn-sm" onclick="delAction()">批量删除</button>
        <span class="pull-right margin-t-5">共有数据：<strong>{{$sections->total()}}</strong> 条</span>
    </div>
    <div class="main-con">
        {{if $sections->count() > 0}}
        <table class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th><input type="checkbox" name="" value=""></th>
                    <th>ID</th>
                    <th>客户端</th>
                    <th>版块名</th>
                    <th>产品数量</th>
                    <th>简要描述</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {{volist name="sections" id="vo" key="key"}}
                <tr id="{{$vo.id}}">
                    <td><input type="checkbox" /></td>
                    <td>{{$vo.id}}</td>
                    <td>{{$vo.client_str}}</td>
                    <td>
                        {{if $vo.type == 'system'}}
                        <i class="iconfont margin-r-2" data-toggle="tooltip" data-placement="top" data-original-title="系统使用，不允许删除">&#xe61b;</i>
                        {{/if}}
                        {{$vo.name}}
                    </td>
                    <td>{{$vo.value_count}}</td>
                    <td title="{{$vo.description}}">{{:mb_strlen($vo.description) > 25 ? mb_substr($vo.description, 0, 25, 'utf-8').'...' : $vo.description}}</td>
                    <td>
                        <a class="btn btn-primary btn-xs" href="{{:url('/admin/section/edit')}}?id={{$vo.id}}">编辑</a>
                        <button type="button" class="btn btn-danger btn-xs" onClick="delAction({{$vo.id}})">删除</button>
                    </td>
                </tr>
                {{/volist}}
            </tbody>
        </table>
        <div class="page">
        {{$sections|raw}}
        </div>
        {{else}}
        <p class="color-red text-center">数据为空！</p>
        {{/if}}
    </div>
</div>
{{include file="layouts/_foot"}}
<script type="text/javascript">
function delAction(id = '')
{
    if (id == '') {
        var trs = $("tbody :checkbox:checked").parents("tr");
        if (trs.length <= 0) {
            layer.msg('请勾选需删除的数据', {icon: 5, time: 1500});
            return false;
        }
        var ids = '';
        for (var i = 0; i < trs.length; i++) {
            ids += trs[i].id+',';
        }
        id = ids.substr(0, ids.length - 1);
    }
    layer.confirm('确认删除？',function(index){
        var load = layer.load();
        $.ajax({
            type: 'GET',
            url: '{{:url("/admin/section/delete")}}?id='+id,
            dataType: 'json',
            success: function(data){
                layer.close(load);
                if (data.code == 200) {
                    layer.msg('提交成功', {time: 1500}, function() {window.location.reload();});
                } else if (data.code == 400) {
                    layer.msg(data.message);
                } else {
                    layer.msg('操作失败');
                }
            },
            error:function(data) {
                console.log(data.msg);
            },
        });     
    });
}    
</script>
</body>
</html>